import { http } from '@/utils/request'
import type {
  Article,
  ArticleCreateRequest,
  ArticleUpdateRequest,
  ArticleListResponse
} from '@/types/api'

// 获取文章列表
export const getArticles = (params?: {
  page?: number
  page_size?: number
  keyword?: string
}): Promise<ArticleListResponse> => {
  return http.get('/api/v1/articles', { params })
}

// 获取文章详情
export const getArticle = (id: number): Promise<Article> => {
  return http.get(`/api/v1/articles/${id}`)
}

// 创建文章
export const createArticle = (data: ArticleCreateRequest): Promise<Article> => {
  return http.post('/api/v1/articles', data)
}

// 更新文章
export const updateArticle = (id: number, data: ArticleUpdateRequest): Promise<Article> => {
  return http.put(`/api/v1/articles/${id}`, data)
}

// 删除文章
export const deleteArticle = (id: number): Promise<void> => {
  return http.delete(`/api/v1/articles/${id}`)
}
